﻿/*
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>

#include "icdbapi.h"

int main(void)
{
	int ret = 0;
	int bounds = 10;
	char* dbName = "orcl";
	char* dbUser = "scott";
	char* dbPswd = "11";

	ICDBHandle handle = NULL;//void * -- ICDBHandle
	ICDBCursor cursor = NULL;

	int deptno = 0;
	char dname[24];
	char loc[24];

	ICDBRow row;
	ICDBField field[10];

	memset(&row, 0, sizeof(ICDBRow));
	memset(field, 0, sizeof(ICDBField) * 3);

	field[0].cont = (char*)&deptno;
	field[0].contLen = 4;

	field[1].cont = (char*)dname;
	field[1].contLen = 24;

	field[2].cont = (char*)loc;
	field[2].contLen = 24;

	//打造内存关系
	row.field = field;
	row.fieldCount = 3;

	//初始化 数据库连接池
	ret = IC_DBApi_PoolInit(bounds, dbName, dbUser, dbPswd);
	if (ret != 0)
	{
		printf("func IC_DBApi_PoolInit() err:%d\n", ret);
		return ret;
	}

	//从连接池中获取一条连接
	ret = IC_DBApi_ConnGet(&handle, 0, 0);
	if (ret != 0)
	{
		printf("func IC_DBApi_ConnGet() err:%d\n", ret);
		return ret;
	}

	//拼接sql语句
	char mySql[2048] = { 0 };
	strcpy(mySql, "select * from dept");
	//或者：char *sql = "insert into dept values(92, '92name姓名', '92loc城市')";

	//游标 是为某一次查询而生 dept是3列
	//创建同时打开游标
	ret = IC_DBApi_OpenCursor(handle, mySql, 3, &cursor);
	if (ret != 0)
	{
		printf("func IC_DBApi_OpenCursor() err:%d\n", ret);
		goto END;
	}

	//打印表头
	printf("%s\t%s\t%s\t\n", "deptno", "dname", "loc");

	while (1)
	{
		deptno = 0;//数据内存重新初始化
		memset(dname, 0, sizeof(dname));
		memset(loc, 0, sizeof(loc));

		ret = IC_DBApi_FetchByCursor(handle, cursor, &row);//一次提取一行，存入row中
		if (ret == 100 || ret == 1403) //IC_DB_NODATA_AFFECT
		{
			break;
		}
		else
		{
			printf("%d\t%s\t%s\t\n", deptno, dname, loc);
		}
	}

	IC_DBApi_CloseCursor(handle, cursor);

END:
	//释放链接，断链修复
	//validFlag 1:不需要修复，0：需要断链修复
	if (ret == IC_DB_CONNECT_ERR)//把链接放到连接池
	{
		IC_DBApi_ConnFree(handle, 0);//需要断链修复
	}
	else
	{
		IC_DBApi_ConnFree(handle, 1);//不需要断链修复
	}

	//释放初始化环境
	IC_DBApi_PoolFree();

	printf("dbapi finish...\n");

	return 0;
}
*/